//
//  WSTools.m
//  LANGirl
//
//  Created by 吴帅 on 16/3/19.
//
//

#import "WSTools.h"

@implementation WSTools

#pragma mark-- 计算内容高度第一步
+ (CGFloat)heightForContent:(NSString *)content font:(CGFloat)font width:(CGFloat)width
{
    //参数1.设置计算高度按照什么样的size来计算
    //注意: 宽度一定与Label宽度一致，高度尽量大一点
    CGSize size = CGSizeMake(width, 10000);
    //参数2.设置计算类型
    //参数3.设置计算内容按照多大字体计算
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:font], NSFontAttributeName, nil];
    //注意: 字体大小也要跟Label字体一样
    //参数4.系统备用参数，设置为nil
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
}

+ (CGFloat)cptStringHeight:(NSString *)string withFont:(UIFont *)font  width:(CGFloat)width
{
    CGSize textBlockMinSize = CGSizeMake(width, 1000);
    CGSize size = CGSizeZero;
    //    if (IOS7Up)
    //    {
    NSStringDrawingOptions options = NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:7];//调整行间距
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,paragraphStyle,NSParagraphStyleAttributeName, nil];
    size = [string boundingRectWithSize:textBlockMinSize
                                options:options
                             attributes:attributes
                                context:nil].size;
    return size.height;
}

@end
